package ru.picman;

import android.graphics.Point;

/**
 * The Pig. This unit is typically controlled by the computer
 * and provides the functionality the computer needs to behave
 * correctly.
 * 
 * @author Matthijs
 */
public class Pig
			 extends Unit
{  
	/**
	 * Constructs the pig. The moving speed is set (to 0.22) and 
	 * the AI is set to PigAI.
	 */
	public Pig() {
		super(EntityType.PIG);
		
		setMoveStep(.12f);
		setAIThread(new PigAI(this));
	}
	
	/**
	 * Sets this pig to frozen or unfrozen. The image will automatically 
	 * change and the pig is no longer allowed to move (if set to frozen).
	 * 
	 * @param frozen true to freeze
	 */
	public void setFrozen(boolean frozen) {
		this.frozen = frozen;
	}

	/**
	 * Checks if the Pig is frozen.
	 * 
	 * @return true if it is
	 */
	public boolean isFrozen() {
	    return frozen;
	}
	
	
	public void moved(int oldX, int oldY) {
		Point p = getPositionI();
		if (!getWorld().isValid(p.x,p.y))
			return;
		Bird bird = (Bird)getWorld().getPlayer().getUnit();
		if (!bird.isImmortal() && collides(bird)) {
			bird.die();
			getWorld().getGame().getGameLoop().addThread(new BirdFlasher(bird,5000));
		}
	}
	
	//
	
	private boolean frozen;
}
